//
//  HDPayoutSectionHeaderView.swift
//  HuaDaoPeifu
//
//  Created by 刘汉琳 on 16/5/17.
//  Copyright © 2016年 paiyipai. All rights reserved.
//

import UIKit

class HDPayoutSectionModel: NSObject {
    
}

class HDPayoutSectionHeaderView: UIView {

    var statusStr:String!
    var casefailModelArray = [HDPayoutCasefailModel]()
    var nameArray = [String]()
    var section:Int!
    var bdatatypeArray = [Int]()
    
    func setupView(){
        
        var messageLeft_X = 0
        let headerView = UIView(frame: CGRect(x: 0,y: 0,width: AppConstant.screenWidth,height: 44))
        addSubview(headerView)

        if statusStr != "-1" && statusStr != "0" {
            headerView.backgroundColor = UIColor(hex:0xffffff)
            messageLeft_X += 10
            createLine()

        }else{
            headerView.backgroundColor = UIColor(hex:0xf7f7f7)

        }
        let icon_imageView = UIImageView()
        headerView.addSubview(icon_imageView)
        icon_imageView.snp.makeConstraints { (make) in
            make.top.equalTo(18)
            make.left.equalTo(15 + messageLeft_X)
            make.width.equalTo(7)
            make.height.equalTo(7)
        }
        icon_imageView.image = UIImage(named: "分类标识")
        let titleLabel = UILabel()
        headerView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.top.equalTo(15)
            make.left.equalTo(icon_imageView.snp.right).offset(5)
            make.width.equalTo(200)
            make.height.equalTo(14)
            
        }
        var isNeed:Bool = false
        for indexNumber in 0..<bdatatypeArray.count{
            
            if section  == bdatatypeArray[indexNumber]{
                isNeed = true
                break
            }
        }
        if isNeed{
            titleLabel.text = backTheDataName(nameArray[section]) + "(" + "必选项" + ")"

        }else{
            titleLabel.text = backTheDataName(nameArray[section])
        }
        titleLabel.font = UIFont.systemFont(ofSize: 14)
        titleLabel.textAlignment = .left
        titleLabel.textColor = UIColor(hex:0x555555)
        for index in 0..<self.casefailModelArray.count {
            let str = self.casefailModelArray[index].datatype
            if str == nameArray[section] {
                icon_imageView.image = UIColor.imageWithColor(UIColor(hex:0xfd3f3f), size: CGSize(width: 7,height: 7))
                icon_imageView.layer.cornerRadius = 3.5
                icon_imageView.layer.masksToBounds = true
                titleLabel.textColor = UIColor(hex:0xfd3f3f)
            }
        }

    }
    
    func createLine(){
        let lineLabel = UILabel()
        self.addSubview(lineLabel)
        lineLabel.snp.makeConstraints { (make) in
            make.top.equalTo(0)
            make.left.equalTo(18)
            make.width.equalTo(1)
            make.bottom.equalTo(0)
        }
        lineLabel.backgroundColor = UIColor(hex:0xd5d5d5)
    }
}
